﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace OpenSearchTests
{
    [TestClass]
    public class GeoCommons
    {
        [TestMethod]
        [DeploymentItem("geocommon_coal_result.xml")]
        public void TestGeoCommonsCoal()
        {
            string responseText = System.IO.File.ReadAllText("geocommon_coal_result.xml");
            OpenSearch.Response response = new OpenSearch.Response(responseText);

            Assert.AreEqual("GeoCommons Search: coal", response.Title);
            List<OpenSearch.ResponseItem> items = response.Items.ToList<OpenSearch.ResponseItem>();
            Assert.AreEqual(12, items.Count);
            OpenSearch.ResponseItem item0 = items[0];
            Assert.AreEqual("Coal Pillar Location-Oil & Gas, Pennsylvania, 2009", item0.Title);
            Assert.AreEqual(3, item0.Links.Count);
            OpenSearch.Link link00 = item0.Links.ToList<OpenSearch.Link>()[0];
            Assert.IsNotNull(link00);
            Assert.AreEqual(new Uri("http://geocommons.com/overlays/11532.html"), link00.Href);
            Assert.AreEqual("alternate", link00.Relation);
            Assert.AreEqual("text/html", link00.MimeType);
            OpenSearch.Link link01 = item0.Links.ToList<OpenSearch.Link>()[1];
            Assert.IsNotNull(link01);
            Assert.AreEqual(new Uri("http://geocommons.com/overlays/11532.kml"), link01.Href);
            Assert.AreEqual("alternate", link01.Relation);
            Assert.AreEqual("application/vnd.google-earth.kml+xml", link01.MimeType);
            OpenSearch.Link link02 = item0.Links.ToList<OpenSearch.Link>()[2];
            Assert.IsNotNull(link02);
            Assert.IsNotNull(link02.RawLink);
            Assert.AreEqual(new Uri("http://geocommons.com/overlays/11532.atom"), link02.RawLink.Uri);
            Assert.AreEqual("application/atom+xml;type=entry", link02.RawLink.MediaType);
            Assert.AreEqual(new Uri("http://geocommons.com/overlays/11532.atom"), link02.Href);
            Assert.AreEqual("edit", link02.Relation);
            Assert.AreEqual("application/atom+xml;type=entry", link02.MimeType);
            Assert.AreEqual("http://geocommons.com/overlays/11532", item0.Id);
            Assert.AreEqual(new DateTime(2009, 04, 03, 21, 24, 43, DateTimeKind.Utc), item0.LastUpdated);
            Assert.AreEqual(1, item0.Contributors.Count);
            Assert.AreEqual("williambenjaminiv", item0.Contributors[0].Name);
            Assert.AreEqual("http://geocommons.com/users/williambenjaminiv", item0.Contributors[0].Uri);
            // TODO:  <category scheme="http://geocommons.com/tags" term="gas, infrastructure, oil"/>
            Assert.AreEqual("Coal Pillar Locations are ", item0.Summary);
            // TODO: <georss:box>39.7216 -80.5116 41.6586 -78.0927</georss:box>
            Assert.IsNotNull(item0.Content);
            Assert.AreEqual("\nCoal Pillar Locations are pillars of coal that must remain in place to provide support for an oil and gas well on the surface.    ", item0.Content.Body);
            Assert.AreEqual("html", item0.Content.MimeType);
        }
    }
}